/**
 ******************************************************************************
 * @file    axi_to_jtag_lm.h
 * @author  KEN
 * @version V2.0
 * @date	Jul. 2nd, 2020
 * @brief	AXI-to-JTAG(Linear Memory) Functions Prototypes
 ******************************************************************************
 * @attention
 *
 * <h2><center>&copy; COPYRIGHT 2020 K'sP</center></h2>
 ******************************************************************************
 */
#ifndef __AXI_TO_JTAG_LM_H
#define __AXI_TO_JTAG_LM_H

#ifdef __cplusplus
extern "C"
{
#endif

#include <stdint.h>
#include <stdbool.h>
#include <stddef.h>

typedef struct AXI_TO_JTAG_LM_CfgTypeDef_s
{
	uint32_t DevID; /*Device ID*/
	uint32_t BaseAddr; /*Base Address*/
	uint32_t mJTAGClkFrequency; /*Module Input Master JTAG Clock Frequency, count in HZ*/
	uint32_t VectorLength; /*JTAG Vector Length*/
} AXI_TO_JTAG_LM_CfgTypeDef;

typedef AXI_TO_JTAG_LM_CfgTypeDef AXI_TO_JTAG_LM_Config;

typedef struct AXI_TO_JTAG_LM_TypeDef_s
{
	volatile uint32_t CR; /*Control Register*/
	volatile uint32_t LENGTH; /*Vector Length Register*/
	volatile uint32_t FREQ_WORD; /*TCK Frequency word Register*/
	volatile uint32_t TMS_MEM_ADDR; /*LM Buffer Start Address(for TMS Vector)*/
	volatile uint32_t TDI_MEM_ADDR; /*LM Buffer Start Address(for TDI Vector)*/
	volatile uint32_t TDO_MEM_ADDR; /*LM Buffer Start Address(for TDO Vector)*/
} AXI_TO_JTAG_LM_TypeDef;

typedef struct AxiJtagLM_InitTypeDef_s
{
	uint32_t TckFrequency; /*TCK Frequency*/
	bool IntEn; /*Jtag Trans Interrupt*/
} AxiJtagLM_InitTypeDef;

typedef struct AxiJtagLM_CmdTypeDef_s
{
	uint32_t Length; /*Vector Length*/
	void* TmsMemPtr; /*LM Buffer Read Pointer(for TMS Vector)*/
	void* TdiMemPtr; /*LM Buffer Read Pointer(for TMS Vector)*/
	void* TdoMemPtr; /*LM Buffer Write Pointer(for TMS Vector)*/
} AxiJtagLM_CmdTypeDef;

typedef struct AxiJtagLM_HandleTypeDef_s
{
	AxiJtagLM_InitTypeDef Init; /*AXI-to-JTAG LM Initialization Structure*/

	AXI_TO_JTAG_LM_CfgTypeDef *Config; /*AXI-to-JTAG LM Hardware Config Structure*/
	AXI_TO_JTAG_LM_TypeDef *Instance; /*AXI-to-JTAG LM Peripheral Instance*/

	AxiJtagLM_CmdTypeDef Cmd; /*Trans Command*/
	bool IsBusy; /*Trans Is busy or not*/
} AxiJtagLM_HandleTypeDef;

int AxiJtagLM_Open(AxiJtagLM_HandleTypeDef *hjtaglm, uint32_t dev_id);
int AxiJtagLM_Config(AxiJtagLM_HandleTypeDef *hjtaglm);
int AxiJtagLM_Shift(AxiJtagLM_HandleTypeDef *hjtaglm, AxiJtagLM_CmdTypeDef *cmd);

int AxiJtagLM_Shift_Async(AxiJtagLM_HandleTypeDef *hjtaglm, AxiJtagLM_CmdTypeDef *cmd);
int AxiJtagLM_Callback(AxiJtagLM_HandleTypeDef *hjtaglm);

#ifdef __cplusplus
}
#endif

#endif